#include"plist.h"

STnode* Buynode(Datatype x)
{
	STnode* newnode = (STnode*)malloc(sizeof(STnode));
	if (newnode == NULL)
	{
		perror("malloc fail");
		return NULL;
	}
	newnode->data = x;
	newnode->next = NULL;
	return newnode;
}
void PushFront(STnode** pphead, Datatype x)
{
	STnode* newnode = Buynode(x);
	
	newnode->next = *pphead;
	*pphead = newnode;
}
void Print(STnode* phead)
{
	STnode* cur = phead;
	while (cur)
	{
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("NULL\n");
}

STnode* swapnode(STnode* pphead)
{

	if (pphead == NULL)
		return NULL;
	STnode* n1 = NULL;
	STnode* n2 = pphead;
	STnode* n3 = n2->next;

	while (n2)
	{
		n2->next = n1;
		n1 = n2;
		n2 = n3;
		if (n3)
			n3 = n3->next;

	}
	return n1;
}